//
//  MYNewsDetailsHotTopicVC.m
//  MuYing
//
//  Created by tbb on 2019/8/6.
//  Copyright © 2019 TBB. All rights reserved.
//

#import "MYNewsDetailsHotTopicVC.h"
#import "MYDynamicDetailsGoodsCell.h"
#import "MYNewsDetailsModel.h"
#import "MYNewsSearchCell.h"
@interface MYNewsDetailsHotTopicVC ()<MYDynamicDetailsGoodsCellDelegate>
@property (nonatomic, strong) MYDynamicDetailsGoodsCell * goodsCell;
@property (nonatomic, assign) CGFloat goodsCellH;

@property (strong, nonatomic) NSMutableArray *catalogArray;
@end

@implementation MYNewsDetailsHotTopicVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.goodsCellH = 50;
}


-(void)setupView {
    [super setupView];
    kYQREGISTERTABLEVIEWCELL([MYNewsDetailsActionTitleCell class])
    [self.listTableView registerNib:[UINib nibWithNibName:@"MYNewsSearchCell" bundle:nil] forCellReuseIdentifier:@"MYNewsSearchCell"];
    kYQREGISTERTABLEVIEWCELL([MYDynamicDetailsGoodsCell class])
}

#pragma mark - UITableViewDelegate, UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 5;
}
- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 2) {
        return 0;
    }else if (section == 3) {
        return self.detailsModel.moreList.count;
    }
    return [super tableView:tableView numberOfRowsInSection:section];
}
- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            MYNewsDetailsActionTitleCell *titleCell = [tableView dequeueReusableCellWithIdentifier:@"MYNewsDetailsActionTitleCell"];
            [titleCell.callBtn setTitle:[NSString stringWithFormat:@"%@\n%@",self.detailsModel.likeNumber,kYQLS(@"点赞")] forState:(UIControlStateNormal)];
            [titleCell.collectionBtn setTitle:[NSString stringWithFormat:@"%@\n%@",self.detailsModel.collectNumber,kYQLS(@"收藏")] forState:(UIControlStateNormal)];
            [titleCell.lookCountBtn setTitle:[NSString stringWithFormat:@"%@\n%@",self.detailsModel.browseNumber,kYQLS(@"用户看过")] forState:(UIControlStateNormal)];
            
            titleCell.titleLb.text = self.detailsModel.name;
            return titleCell;
        }
    }
    if (indexPath.section == 2) {
        MYDynamicDetailsGoodsCell *goodsCell = [tableView dequeueReusableCellWithIdentifier:@"MYDynamicDetailsGoodsCell"];
        goodsCell.collViewH = self.goodsCellH;
        goodsCell.delegate = self;
        self.goodsCell = goodsCell;
        return goodsCell;
    }
    
    if(indexPath.section == 3) {
        
        MYNewsDetailsMoreModel *moreModel = nil;
        if (indexPath.row < self.detailsModel.moreList.count) {
            moreModel = self.detailsModel.moreList[indexPath.row];
        }
        
        MYNewsSearchCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MYNewsSearchCell"];
        cell.timeLb.text = moreModel.title;//@"子初(Springbuds)母婴本色抽纸婴儿抽取式面巾纸家用纸";
        cell.timeLb.text = moreModel.createTimeStr;
        cell.likeCountLb.text = [NSString stringWithFormat:@"%@ %@",kYQLS(@"点赞数"),moreModel.likeNumber];
        [cell.newsIcon setImageWithURL:YQSTRINGTOURL(moreModel.defaultImg) placeholder:nil];
        return cell;
    }
    return [super tableView:tableView cellForRowAtIndexPath:indexPath];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            return 102;
        }
    }else if (indexPath.section == 2) {
        CGFloat w = (kScreenWidth - 34) / 2.0;
        return 0.01;//self.goodsCellH;//(w+70)*2+12+10+18;
    }else if (indexPath.section == 3) {
        return 97;
    }
    return [super tableView:tableView heightForRowAtIndexPath:indexPath];
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    if (section == 2 || section == 3) {
        MYShopDetailsTitleHeaderView *headerView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"MYShopDetailsTitleHeaderView"];
        if (section == 2) {
            //headerView.titleLb.text = @"文章产品";
        }else{
            headerView.titleLb.text = kYQLS(@"相关文章");
        }
        
        return headerView;
        
    }
    return [super tableView:tableView viewForHeaderInSection:section];
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if (section == 2) {
        return 0.01;
    }
    if (section == 2 || section == 3) {
        return 52;
    }
    return [super tableView:tableView heightForHeaderInSection:section];
}
#pragma mark - UITableViewDelegate, UITableViewDataSource end


-(void)didSelectItemAtItem:(NSInteger)item {
    
}
@end
